<?php
// no direct access
defined('_JEXEC') or die;

JLoader::register('ContentHelperRoute', JPATH_SITE.'/components/com_content/helpers/route.php');

abstract class modBPMetaMenuHelper
{
	public static function getCategoryContentMetaKeywords($catid)
	{
    	$db =& JFactory::getDbo();
    	$query = $db->getQuery(true);
    		
	    $query->select('a.metakey');
	    $query->from('#__content AS a');
	    $query->where('a.state = 1');
	    $query->where('a.publish_up = ' . $db->quote('0000-00-00 00:00:00') . ' OR a.publish_up <= ' . $db->quote(date('Y-m-d H:i:s')));
	    $query->where('a.publish_down = ' . $db->quote('0000-00-00 00:00:00') . ' OR a.publish_down >= ' . $db->quote(date('Y-m-d H:i:s')));
	    if ($catid)
	    	$query->where('a.catid = ' . (int) $catid);
	    $query->where('a.metakey != ""');
		$db->setQuery($query);
		
	    $results = array();
		$list = $db->loadObjectList();
		foreach ($list as $item) :
    		if (strstr($item->metakey, ',') !== false) :
    			$multi = explode(',', $item->metakey);
    			foreach ($multi as $metakey) :
    				$results[] = trim($metakey);	
    			endforeach;
    		else :
				$results[] = $item->metakey;
    		endif;
    	$results = array_unique($results);
    	asort($results);
    	endforeach;
   		return $results;
	}
}
